package com.wanghua.mall.coupon.controller;

import java.util.Arrays;
import java.util.Map;

import com.wanghua.common.dto.SkuReductionDto;
import org.springframework.web.bind.annotation.*;

import com.wanghua.mall.coupon.entity.SkuFullReductionEntity;
import com.wanghua.mall.coupon.service.SkuFullReductionService;
import com.wanghua.common.utils.PageUtils;
import com.wanghua.common.utils.R;

import javax.annotation.Resource;


/**
 * 商品满减信息
 *
 * @author wanghua
 * @email 2367279431@qq.com
 * @date 2021-08-25 15:55:27
 */
@RestController
@RequestMapping("/coupon/skufullreduction")
public class SkuFullReductionController {

    @Resource
    private SkuFullReductionService skuFullReductionService;

    /**
     * 供product调用，保存sku的满减、优惠信息
     */
    @PostMapping("/saveSkuReductionDto")
    public R saveSkuReductionDto(@RequestBody SkuReductionDto skuReductionDto) {
        skuFullReductionService.saveSkuReductionDto(skuReductionDto);
        return R.ok();
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = skuFullReductionService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        SkuFullReductionEntity skuFullReduction = skuFullReductionService.getById(id);
        return R.ok().put("skuFullReduction", skuFullReduction);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SkuFullReductionEntity skuFullReduction) {
        skuFullReductionService.save(skuFullReduction);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody SkuFullReductionEntity skuFullReduction) {
        skuFullReductionService.updateById(skuFullReduction);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        skuFullReductionService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
